package models.user;

import models.*;
import play.data.format.Formats;
import play.data.validation.Constraints;
import play.db.ebean.Model;

import javax.persistence.*;

import java.util.*;

/**
 * User: yeqingzhou
 * Date: 12-8-30
 */
@Entity
public class AniUserRole extends Model {
	
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
    public Long id;
    
    @Constraints.Required
    @Formats.NonEmpty
    public String roleKey;
    
    @Transient
    //@OneToMany(mappedBy="role")
    public List<AniUser> users;
    
    public AniUserRole(){}

    public AniUserRole(Long id, String roleKey) {
		super();
		this.id = id;
		this.roleKey = roleKey;
	}
    
    public AniUserRole(String roleKey) {
		super();
		this.roleKey = roleKey;
	}

	// -- Queries

    public static Model.Finder<Long, AniUserRole> find = new Model.Finder(Long.class, AniUserRole.class);

    public static List<AniUserRole> findAll() {
        return find.all();
    }

    public static AniUserRole findByRoleKey(String roleKey) {
        return find.where().eq("roleKey", roleKey).findUnique();
    }
    
    public enum RoleKeys{
    	ANI_ADMIN,
    	ANI_USER
    }

}
